﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using StockFinder.StockLists.SymbolListEnumerators;
using StockFinder.Model;
using StockFinder.IBD;
using StockFinder.StockLists.Exchanges;

namespace StockFinder.StockLists
{
    public class MarketSmithAndNasdaqOnlineYahooFinanceOnlineStockList : YahooFinanceOnlinePriceLoaderSymbolListEnumerator
    {
        protected override List<Symbol> GetSymbols()
        {
            var symbols = new List<Symbol>();

            //1 get list of marketsmith stocks
            var ibd = new IBDRatingDatabaseUpdater();
            ibd.LoadFromFile();
            if (Cache.IBDRatingsList != null && Cache.IBDRatingsList.Count > 0)
            {
                Cache.IBDRatingsList.ForEach(r => symbols.Add(new Symbol { Name = r.Symbol }));
            }

            //2 get list of nasdaq online stocks
            var nasdaqOnlineStockList = new NasdaqOnlineAllYahooFinanceOnlinePricesStockList() { LoadPrices = false };
            foreach (var item in nasdaqOnlineStockList)
            {
                var match = symbols.Find(s => s.Name == item.Name);

                if (match == null)
                {
                    symbols.Add(item);
                }
            }

            symbols.Sort((l, r) => string.Compare(l.Name, r.Name));

            return symbols;
        }
    }
}
